< previous page page_354 next page >

Page 354
Tip.gif
You can also create a QueryDef that is not added to the QueryDefs collection. Simply execute the CreateQueryDef method with an empty name:
set qd = db.CreateQueryDef("")
You can then fill the SQL property of the query and execute it to get the resulting dataset. When you close the query, it is destroyed instead of being saved to the QueryDefs collection. This is especially handy when you want to execute dynamic SQL statements, but do not want to create and delete QueryDefs at runtime.

Getting Results from QueryDefs
There are two basic methods for working with QueryDefsExecute and OpenRecordset. The Execute method is used to perform SQL action queries. Action queries are SQL statements that perform some action on the data table. Examples of action queries are SQL statements that
· Add, modify, or remove table records
· Add indexes or relationship rules
· Add, modify, or remove tables from the database
The other method used when working with QueryDefs is the OpenRecordset method. This method is used to retrieve data from the tables into a programming object for manipulation.
Add another button to the form. Set its Name property to cmdRunningQDs and its Caption to Running QDs. Now enter the code from Listing 9.21 into the cmdRunningQDs_Click event
Type.gifListing 9.21. Coding the cmdRunningQDs_Click event.
Private Sub cmdRunningQDs_Click()
    '
    ' running stored queries
    '
    On Error GoTo LocalErr
    '
    Dim ws As Workspace
    Dim db As Database
    Dim qd As QueryDef
    Dim rs As Recordset
    Dim pr As Property
    '
    Dim strDBName As String
    Dim strQDName As String

 
< previous page page_354 next page >

If you like this book, buy it!